public class Piece {
    static final tBin = 'bin'
    static final tJu = 'ju'
    static final tMa = 'ma'
    static final tPao = 'pao'
    static final tShi = 'shi'
    static final tXiang = 'xiang'
    static final tJiang = 'jiang'
    static final TypeList = [tBin, tJu, tMa, tPao, tXiang, tShi, tJiang]

    static final cBlack = 'black'
    static final cRed = 'red'
    static final ColorList = [cRed, cBlack]

    int typeIndex
    int colorIndex
    int x, y
    boolean alive

    static belongsTo = [game: Game]

    Piece() {
        this.typeIndex = 0
        this.colorIndex = 0
        this.x = 0
        this.y = 0
        this.alive = false
    }

    Piece(String t, String c, int x, int y) {
        this.typeIndex = this.TypeList.indexOf(t)
        this.colorIndex = this.ColorList.indexOf(c)
        this.x = x
        this.y = y
        this.alive = true
    }

    String color() {
        return ColorList[colorIndex]
    }

    String type() {
        return TypeList[typeIndex]
    }

    String toString() {
        return TypeList[typeIndex] + '_' + ColorList[colorIndex] + " at [" + x + ":" + y + "] is " + ( alive?"alive":"dead")
    }
}